extends 基础场景类
@onready var red_ai_option : OptionButton= %RedAiOption
@onready var black_ai_option : OptionButton= %BlackAiOption
@onready var 棋谱option: OptionButton = %"棋谱Option"
@onready var 棋局预览 = %"棋局预览"
@onready var load_button = %loadButton
@onready var load_check_button = %loadCheckButton

var 当前棋谱:棋谱数据类:
	set(value):
		当前棋谱=value
		棋局预览.初始化棋局(当前棋谱)

func _ready():
	初始化下拉框()
	预览当前棋局()
	load_button.disabled=true

func 初始化下拉框():
	for 难度 in GameGlobal.AI难度集.keys():
		red_ai_option.add_item(难度)
		black_ai_option.add_item(难度)
		
	black_ai_option.select(1)
		
	for 棋谱 in GameGlobal.棋谱集:
		if 棋谱.胜率<0:
			棋谱option.add_item(棋谱.id+" "+棋谱.中文名)
		else:
			棋谱option.add_item(棋谱.id+" "+棋谱.中文名+"(胜率:"+str(棋谱.胜率*100)+"%)")
	
func _on_button_pressed():
	var red_ai_key=GameGlobal.AI难度集.keys()[red_ai_option.selected]
	GameGlobal.红棋AI=GameGlobal.AI难度集[red_ai_key]
	
	var black_ai_key=GameGlobal.AI难度集.keys()[black_ai_option.selected]
	GameGlobal.黑棋AI=GameGlobal.AI难度集[black_ai_key]
		
	var 棋局=GameViewManager.切换场景("棋局")
	GameGlobal.当前棋谱=当前棋谱
	棋局.初始化棋局(当前棋谱)

func _on_棋谱option_item_selected(_index):
	预览当前棋局()

func 预览当前棋局():
	var 棋谱=GameGlobal.棋谱集[棋谱option.selected]
	当前棋谱=棋谱

func _on_load_button_pressed():
	var 载入FEN=GameViewManager.打开弹窗("载入FEN")
	载入FEN.发送FEN.connect(当发送FEN)
	
func 当发送FEN(FEN:String):
	var 棋谱:棋谱数据类=棋谱数据类.new()
	棋谱.id="临时FEN"
	棋谱.中文名="临时棋局"
	棋谱.红先棋局=FEN
	棋谱.红最长=-1
	当前棋谱=棋谱

func _on_load_check_button_pressed():
	load_button.disabled=!load_button.disabled
	棋谱option.disabled=!棋谱option.disabled
